package com.itheima.consumer.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author wyh
 * @Date 2025/5/8 20:48
 * @description:
 */
//@Configuration
public class FanoutConfiguration {
    // 声明FanoutExchange交换机
    @Bean
    public FanoutExchange fanoutExchange() {
//        return ExchangeBuilder.fanoutExchange("fanout.hmall").build();
        return new FanoutExchange("fanout.hmall");
    }

    // 声明队列
    @Bean
    public Queue fanoutQueue1() {
//        return QueueBuilder.durable("fanout.queue1").build();
        return new Queue("fanout.queue1");
    }

    // 声明队列与交换机的绑定关系
    @Bean
    public Binding fanoutBinding1(Queue fanoutQueue1, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }
    @Bean
    public Queue fanoutQueue2() {
//        return QueueBuilder.durable("fanout.queue1").build();
        return new Queue("fanout.queue2");
    }

    @Bean
    public Binding fanoutBinding2(Queue fanoutQueue2, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }
}
